﻿using System;
using System.Collections.Generic;
using System.Text;

using System.Data.SqlClient;
using System.Data.OracleClient;
using System.Data.OleDb;


namespace DataBaseAccessLib
{
    /// <summary>
    /// 使用数据库类型

    /// </summary>
    public enum DBType
    {
        /// <summary>
        /// sql Server 数据库

        /// </summary>
        SQL,

        /// <summary>
        /// Oracle 数据库

        /// </summary>
        ORACLE,

        /// <summary>
        /// ACCESS 数据库

        /// </summary>
        ACCESS
    }

    /// <summary>
    /// 获取访问数据库的对象类

    /// </summary>
    public class DBFactory
    {
        /// <summary>
        /// 获取访问数据库的对象
        /// </summary>
        /// <param name="type">数据库类别</param>
        /// <param name="connectionString">连接字符串</param>
        /// <returns>数据库的对象</returns>
        public static IDBAccess GetDBAccess(DBType type, string connectionString)
        {
            System.Diagnostics.Debug.Assert(connectionString.Length > 0);

            IDBAccess DB = null;

            switch (type)
            {
                case DBType.ORACLE:
                    DB = new DBAccess<OracleConnection, OracleCommand, OracleDataAdapter>(connectionString);
                    break;

                case DBType.SQL:
                    DB = new DBAccess<SqlConnection, SqlCommand,SqlDataAdapter>(connectionString);
                    break;

                case DBType.ACCESS:
                    DB = new DBAccess<OleDbConnection, OleDbCommand, OleDbDataAdapter>(connectionString);
                    break;
            }

            return DB;
        }
    }
}
